package com.jahentao.integration;

import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

/**
 * Created with IntelliJ IDEA.<br>
 * Description: Spring整合ActiveMQ 生成者<br>
 * User: jahen<br>
 * Date: 2017-04-03<br>
 * Time: 14:42<br>
 */
public class SpringProducer {
    //Spring的模板，封装了很多功能
    private JmsTemplate jmsTemplate;

    public void setJmsTemplate(JmsTemplate jmsTemplate) {
        this.jmsTemplate = jmsTemplate;
    }

    public void send() {
        //使用JMSTemplate可以很简单的实现发送消息
        jmsTemplate.send(new MessageCreator() {
            public Message createMessage(Session session) throws JMSException {
                System.out.println("发送消息: jmsTemplate send messages");
                return session.createTextMessage("jmsTemplate send messages");
            }
        });
    }
}
